﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using componentXtra;
using System.Drawing.Drawing2D;

namespace Integrador
{
    public partial class Form2 : Form
    {
        List<double> tiempo = null;
        Dinamica dinamica = null;
        double tiempoTotal;
        double tamanoPaso;
        double[] rot = null;
        int limpiar;


        public Form2()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            double rotores = (double)this.numericUpDown1.Value;
            for (int i = 0; i<this.rot.Length; i++)
            {
                rot[i] = rotores;
            }
            Estado estadoActual = this.dinamica.IntegraPaso(ref this.tiempoTotal, this.tamanoPaso, this.rot);
            PintaGrafica(tiempoTotal, estadoActual.Z, this.xyGraph1);

        }
        private void IniciaModelo()
        {
            Estado estadoInicial = new Estado(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            rot = new double[4];
            rot.ToList<double>().ForEach(x => x = 0);
            this.dinamica = new Dinamica(rot, estadoInicial);
            //tamaño del paso en segundos(no inferior a 0.01)
            //this.tamanoPaso = timer1.Interval / 1000.0;
            this.tamanoPaso = 0.5;
            this.tiempoTotal = 0;
            this.limpiar = 1;
            

        }

        private void button1_Click(object sender, EventArgs e)
        {
            IniciaModelo();
            timer1.Enabled = true;
        }
        private void LimpiaGraficas()
        {
            this.xyGraph1.ClearGraphs();

        }
        private void PintaGrafica(double tiempo, double valor, XYGraph grafica)
        {

            grafica.AddGraph("", DashStyle.Solid, Color.Yellow, 0, false);
            grafica.AddValue(0, (float)tiempo, (float)valor);
            grafica.DrawAll();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
           
        }

    }
}
